package com.example.et.controller;

import java.sql.SQLException;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.et.entity.User;
import com.example.et.mapper.UserMapper;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserMapper userMapper;
    /** 增添数据 */
    @PostMapping("/insert")
    public Object insert(String name) {
        User user = new User();
        user.setName(name);
        return userMapper.insert(user);
    }
    /** 查询数据 */
    @GetMapping("/show")
    public Object show() {
        return userMapper.getAllUser();
    }
    /** 删除数据 */
    @DeleteMapping("/delete")
    public Object delete(Integer id) {
        return userMapper.deleteById(id);
    }
    /** 修改数据 */
    @PutMapping("update")
    public Object update(Integer id, String name) {
        User user = new User();
        user.setId(id);
        user.setName(name);
        return userMapper.updateById(user);
    }
}
